<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;

class Param extends Model
{
    use ModelTree, AdminBuilder;

    protected $fillable = ['name', 'introduction', 'parent_id', 'order'];

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $this->setOrderColumn('sort');
        $this->setTitleColumn('name');
    }

    public function children()
    {
        return $this->hasMany(Param::class, 'parent_id');
    }
}
